/**
 * 
 */
package com.effectiv.req1.security;

import java.util.List;

import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

import com.effectiv.req1.domain.Lov;
import com.effectiv.req1.domain.User;


/**
 * @author Dhrubo
 *
 */
public abstract class SecurityUtil {
	
	public static User getUserDetails() {
		SecurityContext ctx = SecurityContextHolder.getContext();
		SimpleUserDetails userDetails = (SimpleUserDetails) ctx.getAuthentication().getPrincipal();
		return userDetails.getUser();
	}
	
	public static boolean isCompanyAdmin(){
		User user = getUserDetails();
		List<Lov> roles = user.getRoles();
		
		boolean companyAdmin = false;
		
		for(Lov l : roles){
			if("ROLE_COMPANY_ADMIN".equals(l.getName())){
				companyAdmin = true;
				break;
			}
		}
		
		return companyAdmin;
		
	}
}

